<%--
  Created by IntelliJ IDEA.
  User: 杨麟
  Date: 2022/2/17
  Time: 17:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.util.List" %>
<%@ page import="com.ysl.bean.UserDemo" %>
<%@ page import="java.util.Arrays" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Main</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/bootstrap.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.js"></script>
</head>
<body>
<div class="container">
    <c:if test="${username == null}"><script>window.location.href ="${pageContext.request.contextPath}//ServletMain?cmd=main";</script></c:if>
    <div class="col-md-10">
        <h1>用户列表</h1>
        <h3>欢迎您 <span>${username}
            </span><a href="${pageContext.request.contextPath}/ServletMain?cmd=dellogin">退出</a><br>
        </h3>



        <form action="${pageContext.request.contextPath}/ServletMain?cmd=main" class="form-inline form-group" method="post" name="form1" >
            <input type="hidden" name="p" id="p" >
            姓名：<input type="text" class="form-control" name="username" value="${Condition.username}" >
            学历：<select name="eid" class="form-control" >
            <option value="" selected >---请选择---</option>
            <c:forEach items="${Education}" var="education">
                <option value="${education.eid}"
                        <c:if test="${education.eid == Condition.eid}">selected</c:if>>${education.ename}
                </option>
            </c:forEach>
        </select>
            开始时间：<input type="date" class="form-control" name="stackdate" value="${Condition.stackdate}">
            结束时间：<input type="date" class="form-control" name="enddate" value="${Condition.enddate}">
            <input type="submit" class="btn btn-info" value="查询">

<%--        <from action="${pageContext.request.contextPath}/page/error.jsp" method="post">--%>
<%--            --%>
<%--        </from>--%>
            <br><br>
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>学历</th>
            <th>住址</th>
            <th>生日</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${pageBean.userDemos}" var="user" varStatus="vs">
            <tr>
                <td>${user.id}</td>
                <td>${user.userName}</td>
                <td>${user.sex}</td>
                <td>${user.ename}</td>
                <td>${user.address}</td>
                <td>${user.birthday}</td>
                <td>
                    <a href='javascript:del(${user.id})' class="btn btn-danger">删除</a>
                    <a href='${pageContext.request.contextPath}/ServletMain?cmd=updateInfo&id=${user.id}' class="btn btn-default">修改</a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <p>
        <span class="col-md-8">
            共${pageBean.pageTotal}条记录，第${pageBean.p}页/共${pageBean.pageCount}页&nbsp;&nbsp;&nbsp;
        <a href="javascript: toPage(1)">首页</a> &nbsp;
        <a href= "javascript: toPage(${pageBean.p-1})">上一页</a> &nbsp;
        <a href="javascript: toPage(${pageBean.p+1})">下一页</a> &nbsp;
        <a href="javascript: toPage(${pageBean.pageCount})">尾页</a> &nbsp;
        跳转至
            <select class="form-control" onchange="toPage(this.value)">
                <c:forEach var="i" begin="1" end="${pageBean.pageCount}" step="1">
                    <option value="${i}" <c:if test="${i==pageBean.p}">
                        selected</c:if>>${i}</option>
                </c:forEach>
            </select>&nbsp;页
        </span>
    </p>
    </form>
    </div>
</div>
</body>
<script>
    function del(id){
        if(confirm("是否删除")){
            window.location.href ="${pageContext.request.contextPath}/ServletMain?cmd=del&id="+id;
        }
    }
    function toPage(p){
        $("#p").val(p);
        document.form1.submit();
    }
</script>
</html>
